﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace NGUYENTHANHDONG.Excercise_lv2.Bai2
{
    public partial class Octagon : Form
    {
        public Octagon()
        {
            InitializeComponent();
        }

        private void Octagon_Load(object sender, EventArgs e)
        {
            cmbKetQua.Items.Add("Chu Vi");
            cmbKetQua.Items.Add("Diện Tích");
            cmbKetQua.SelectedIndex = 0;

            txtKetQua.Enabled = false;
        }

        private void btnXacNhan_Click(object sender, EventArgs e)
        {
            errorProvider1.Clear();

            if(string.IsNullOrEmpty(txtSide.Text))
            {
                errorProvider1.SetError(txtSide, "Khong dc de trong !!");
                txtSide.Focus();
            }
            else
            {
                UserEntity objUser;
                CONTROLLERS con = new CONTROLLERS();
                if(cmbKetQua.Text == "Chu Vi")
                {
                    objUser = new UserEntity(double.Parse(txtSide.Text), 1);
                    txtKetQua.Text = con.tinhtoan(objUser) + " ";
                }
                else if (cmbKetQua.Text == "Diện Tích")
                {
                    objUser = new UserEntity(double.Parse(txtSide.Text), 2);
                    txtKetQua.Text = con.tinhtoan(objUser) + " ";
                }
            }
        }
    }
}
